package com.lovo.project.servlet.petOwner;

import com.lovo.project.exception.OurException;
import com.lovo.project.model.PetOwnDO;
import com.lovo.project.service.PetOwnService;
import com.lovo.project.service.impl.PetOwnServiceImpl;
import com.lovo.project.vo.ResultVO;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "FindByPetOwnerIdServlet",value = "/petOwner/findByPetOwnerId")
public class FindByPetOwnerIdServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       try {
           Integer id = Integer.parseInt(request.getParameter("id"));
           PetOwnService service = new PetOwnServiceImpl();
           PetOwnDO pd = service.selectById(id);
           response.getWriter().print(ResultVO.success().add(pd).toJson());
       }catch (OurException o){
           response.getWriter().print(ResultVO.fail(o.getCodeEnum()));
       }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
